package com.dolphin.common.calc;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author shida
 */
@Setter
@Getter
@ToString
public class VarValue {

    private ComputeStatusEnum status;

    private Object result;
    private String error;
    private String varName;
    private String varCode;
    private String bid;

    public VarValue(Object result, String varName, String varCode, String bid) {
        this(ComputeStatusEnum.SUCCESS, result, varName, varCode, bid);
    }

    public VarValue(ComputeStatusEnum status, Object result, String varName, String varCode, String bid) {
        this.status = status;
        this.result = result;
        this.varName = varName;
        this.varCode = varCode;
        this.bid = bid;
    }

    public boolean isSuccess(){
        return ComputeStatusEnum.SUCCESS.equals(this.status);
    }

    public void fail(ComputeStatusEnum status, String error){
        setStatus(status);
        setResult(result);
    }

    public void fail(String error){
        fail(ComputeStatusEnum.FAIL, error);
    }

    public void success(Object result){
        setStatus(ComputeStatusEnum.SUCCESS);
        setResult(result);
    }

}
